package cn.itlaobing.dao;

import cn.itlaobing.dao.ResultSetHandler.GoodResultSerHandler;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 类名: cn.itlaobing.dao
 * 功能:  商品数据访问层
 * 作者: 王博
 * 日期: 2017/11/14 9:07
 */
public class ItlbGoodsDao extends  BaseDao {
    /*
        查询热销商品
     */
    public List<Map<String, Object>> QuerySix() throws SQLException {
        String sql="SELECT id,good_name,price,picUrl FROM itlb_goods ig LEFT JOIN (\n" +
                "                SELECT good_id,COUNT(buy_count) bycount FROM itlb_order_details) s\n" +
                "                ON ig.id=s.good_id  LEFT JOIN itlb_goods_pic igp ON igp.goodsId=ig.id\n" +
                "                 AND ig.status_line =1\n" +
                "                ORDER BY s.bycount limit 0,6";
        QueryRunner queryRunner=new QueryRunner(getDataSource());
        List<Map<String,Object>> mapList=queryRunner.query(sql,new GoodResultSerHandler());
        return mapList;
    }
    /*
        查询最新上架
     */
    public List<Map<String, Object>> veryLatest() throws SQLException {
        String sql="SELECT ig.id,ig.good_name,ig.price,igp.picUrl FROM itlb_goods ig LEFT JOIN itlb_goods_pic igp ON ig.id=igp.goodsId AND ig.good_new=1\n" +
                " ORDER BY orders_weight DESC limit 0,6";
        QueryRunner qr=new QueryRunner(getDataSource());
        return qr.query(sql,new GoodResultSerHandler());
    }
}
